class TreeNode:
    def __init__(self, x, left=None, right=None):
        self.val = x
        self.left = left
        self.right = right


class Solution:
    def _level_order(self, root: TreeNode, now_level: int):
        if len(self.result) <= now_level:
            self.result.append([])
        if root.left:
            self._level_order(root.left, now_level+1)
        if root.right:
            self._level_order(root.right, now_level+1)
        self.result[now_level].append(root.val)


    def levelOrderBottom(self, root: TreeNode) -> 'List[List[int]]':
        self.result = []
        if root:
            self._level_order(root, 0)
        self.result.reverse()
        return self.result
        

if __name__ == "__main__":
    s = Solution()
    print(s.levelOrderBottom(TreeNode(3, left=TreeNode(9), right=TreeNode(20, left=TreeNode(15), right=TreeNode(7)))))
